11081. Electronic
lock
The traitors blocked the doors again. And
to open them, you must enter the code.
The field for entering the code is an
endless sequence of 7-segment indicators. It is known that the code is the
largest positive integer, for displaying which no more than n burning
segments are used.
Help the team find out the code.
Input. The first line contains one integer n (2 ≤ n ≤ 105) – the
maximum number of burning segments when displaying the number.
Output. Print one number – the required code.
Sample
input |
Sample output |
6 |
111 |
constructive
If n is even, then it is preferrable
to use only ones to maximize the code. Print n / 2 ones.
If n is odd, print 7 as the first
digit, and then print (n – 3) / 2 ones.
Example
For n = 8 the answer
is 1111.
For n = 9 the answer
is 7111.
For n = 10 the answer is 11111.
Read the input value of n.
scanf("%d", &n);
If n
is odd, then print 7 as the first digit.
if (n % 2 == 1)
{
printf("7");
Decrease n
by 3 because 3 burning segments are used for digit 7.
n -= 3;
}
Print n / 2 ones.
while (n > 0)
{
printf("1");
n -= 2;
}
printf("\n");